package me.zhengjie.modules.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.modules.system.converter.MachineConverter;
import me.zhengjie.modules.system.domain.entity.CheckRecords;
import me.zhengjie.modules.system.domain.req.CheckRecordsReqDTO;
import me.zhengjie.modules.system.domain.req.CheckRecordsReqQueryDTO;
import me.zhengjie.modules.system.domain.rsp.CheckRecordsRspDTO;
import me.zhengjie.modules.system.mapper.CheckRecordsMapper;
import me.zhengjie.modules.system.service.CheckRecordsService;
import me.zhengjie.utils.PageResult;
import me.zhengjie.utils.PageUtil;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
@RequiredArgsConstructor
@Slf4j
public class CheckRecordsServiceImpl extends ServiceImpl<CheckRecordsMapper, CheckRecords> implements
        CheckRecordsService {


    /**
     * 添加
     *
     * @param reqDTO
     */
    @Transactional(rollbackFor = Exception.class)
    public Boolean save(CheckRecordsReqDTO reqDTO) {
        log.info("存储用户信息---------------");
        CheckRecords checkRecords = MachineConverter.INSTANCE.checkRecordsReqDTOTo(reqDTO);
        return super.save(checkRecords);
    }


    /**
     * 列表
     *
     * @param reqQueryDTO
     * @return
     */
    public ResponseEntity<PageResult<CheckRecordsRspDTO>> findAll(CheckRecordsReqQueryDTO reqQueryDTO) {
        PageHelper.startPage(reqQueryDTO.getPage(), reqQueryDTO.getSize(), true);
        List<CheckRecordsRspDTO> list = getBaseMapper().findAll(reqQueryDTO);
        PageInfo<CheckRecordsRspDTO> pageInfo = new PageInfo<>(list);
        return ResponseEntity.ok(PageUtil.toPage(pageInfo.getList(), pageInfo.getTotal()));
    }

}
